<template>
  <div class="Mymain">
    <div class="Mymain-contain">
      <div class="Mymain-contain-head">
        <div class="Mymain-contain-head-user">
          <img
            v-if="username !== '请登录'"
            class="Mymain-contain-head-user-ava"
            src="https://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTIbGHib4GpT7ytM0VaBsN8VOTR7mV1ka5iaSZ2icGct6ibhvVvqBW6IibSYibqgqqeO79PTWroGWzEAjtaA/132"
            alt=""
          />
          <img
            v-else
            class="Mymain-contain-head-user-ava"
            src="https://cube.elemecdn.com/3/7c/3ea6beec64369c2642b92c6726f1epng.png"
            alt=""
          />

          <div style="display: flex; flex-direction: column; margin: 20px">
            <span class="Mymain-contain-head-user-name">{{
              this.username
            }}</span>
            <span class="Mymain-contain-head-user-sign">暂无个性签名</span>
          </div>
        </div>
        <a href="javaScript:;" class="logout" @click="logout">[退出]</a>
        <el-tabs
          v-model="this.activeName"
          type="card"
          style="margin-top: 40px"
          @click="handleClick"
        >
          <el-tab-pane label="主页" name="first">
            <div class="body">
              <div class="body-l">书山有路勤为径</div>
              <div class="body-r">
                <div class="body-r-ru">
                  <div class="body-r-ru-span">
                    <span class="body-r-ru-span-num">{{ discuss }}</span>
                    <br />
                    <span class="body-r-ru-span-name">讨论数</span>
                  </div>
                  <div class="body-r-ru-span">
                    <span class="body-r-ru-span-num">0</span>
                    <br />
                    <span class="body-r-ru-span-name">评论数</span>
                  </div>
                  <div class="body-r-ru-span">
                    <span class="body-r-ru-span-num">0</span>
                    <br />
                    <span class="body-r-ru-span-name">学习数</span>
                  </div>
                </div>
                <div class="body-r-rd">
                  <p style="font-size: 26px">账号信息：</p>
                  昵称：{{ username }} <br />
                  专业：未填写 <br />
                  粉丝：0 <br />
                  关注：0 <br />
                  <el-button
                    v-if="username !== '请登录'"
                    @click="onExit"
                    type="danger"
                    style="text-align: center"
                    plain
                    round
                    >退出登陆</el-button
                  >
                </div>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane :label="'收藏 ' + this.favData.length" name="2">
            <div class="favorite">
              <div class="favorite-container">
                <transition-group tag="ul" class="favorite-container-course">
                  <li
                    v-for="item in favData"
                    :key="item"
                    class="favorite-container-course-item"
                    @click="toDetial(item)"
                  >
                    <div>
                      <img
                        class="favorite-container-course-item-img"
                        src="@/assets/course/cover.jpg"
                        alt=""
                      />
                    </div>
                    <p class="favorite-container-course-item-p">
                      {{ item.name }}
                    </p>
                  </li>
                </transition-group>
              </div>
            </div>
          </el-tab-pane>
          <el-tab-pane :label="'历史 ' + this.hisData.length" name="4">
            <div class="history">
              <div class="history-container">
                <transition-group tag="ul" class="history-container-course">
                  <li
                    v-for="item in hisData"
                    :key="item"
                    class="history-container-course-item"
                    @click="toDetial(item)"
                  >
                    <div>
                      <img
                        class="history-container-course-item-img"
                        src="@/assets/course/cover.jpg"
                        alt=""
                      />
                    </div>
                    <p class="history-container-course-item-p">
                      {{ item.name }}
                      {{ item.date }}
                    </p>
                  </li>
                </transition-group>
              </div>
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
    </div>
  </div>
</template>
<script>
import * as types from "../store/types";
import GLOBAL from "@/api/global_var";
export default {
  activated: function () {
    this.discuss = GLOBAL.discuss;
    this.favData = GLOBAL.Favorite;
    this.hisData = GLOBAL.History;
    console.log(GLOBAL.Favorite);
  },
  mounted: function () {
    if (localStorage.getItem("username")) {
      this.dialogFormVisible = false;
      this.username = localStorage.getItem("username");
    } else {
      this.dialogFormVisible = true;
    }
  },
  data() {
    return {
      hisData: [],
      favData: [],
      discuss: "0",
      activeName: "first",
      dialogFormVisible: "",
      username: "请登录",
      form: {
        name: "",
        passwd: "",
      },
      itemData: [
        {
          name: "机械原理",
          url: "//player.bilibili.com/player.html?aid=55573008&bvid=BV1w4411N7fD&cid=97155262&page=1",
          cover:
            "http://i0.hdslb.com/bfs/archive/d7f0c41f1642a305f2f8ee7d73fd1e2901b465d4.jpg",
        },
      ],
    };
  },
  methods: {
    toDetial(res) {
      console.log(res);
      this.$router.push({
        name: "2",
        params: {
          res: res,
        },
      });
    },
    onExit() {
      localStorage.setItem("username", "");
      location.reload();
    },
    onConfirm() {
      this.dialogFormVisible = false;
      localStorage.setItem("username", this.form.name);
      this.username = this.form.name;
      console.log("submit!");
    },
    logout() {
      this.$store.commit(types.LOGOUT);
      this.$router.push({
        path: "/login",
      });
    },
    handleClick() {},
  },
};
</script>
<style lang="scss" scoped>
.Mymain {
  width: 100%;
  height: 100%;
  &-contain {
    margin: auto;
    width: 65%;
    height: 100%;
    &-head {
      height: 250px;
      width: 100%;
      background: url("../assets/userbanner.jpeg") no-repeat;
      background-size: 100% 100%;
      &-user {
        padding-top: 130px;
        padding-left: 30px;
        display: flex;
        flex-direction: row;
        &-ava {
          width: 80px;
          height: 80px;
          border-radius: 50%;
          padding: 2px;
          border: 1px solid #dadada;
        }
        &-name {
          flex: 1;
          color: white;
          font-weight: 600;
          font-size: 20px;
        }
        &-sign {
          flex: 1;
          //font-weight: 600;
          color: white;
          font-size: 14px;
        }
      }
    }
  }
}
.body {
  display: flex;
  width: 100%;
  height: 500px;
  margin-bottom: 20px;
  margin-top: 20px;
  &-l:hover {
    box-shadow: 0px 5px 20px grey;
    border-radius: 10px;
  }
  &-l {
    transition: 0.5s;
    flex: 2.5;
    border: 1px solid #dadada;
    padding: 20px;
    margin-left: 20px;
    margin-right: 20px;
    color: #333333;
  }
  &-r {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-right: 20px;
    &-ru:hover {
      box-shadow: 0px 5px 20px grey;
      border-radius: 10px;
    }
    &-ru {
      transition: 0.5s;
      flex: 1;
      border: 1px solid #dadada;
      background: white;
      //box-shadow: 0px 5px 20px grey;
      //border-radius: 10px;
      padding: 20px;
      margin-bottom: 20px;
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: center;
      &-span {
        text-align: center;
        display: flex;
        flex-direction: column;
        &-num {
          font-weight: 900;
          font-size: 24px;
        }
        &-name {
          color: #333333;
        }
      }
    }
    &-rd:hover {
      box-shadow: 0px 5px 20px grey;
      border-radius: 10px;
    }
    &-rd {
      transition: 0.5s;
      flex: 3;
      border: 1px solid #dadada;
      color: #333333;
      padding: 0 20px 20px 20px;
      line-height: 40px;
    }
  }
}
.favorite {
  width: 100%;
  height: 500px;
  margin-top: 20px;
  margin-bottom: 20px;
  width: 100%;
  &-container:hover {
    box-shadow: 0px 5px 20px grey;
    border-radius: 10px;
  }
  &-container {
    transition: 0.5s;
    flex: 2.5;
    border: 1px solid #dadada;
    padding: 0px;
    margin-left: 20px;
    margin-right: 20px;
    color: #333333;
    height: 100%;
    &-course {
      &-item:hover {
        transform: translateY(-10px);
        box-shadow: 0px 10px 30px #888888;
      }
      &-item {
        list-style: none;
        float: left;
        width: 219px;
        height: 180px;
        margin-top: 10px;
        margin-left: 10px;
        transition: all 0.3s;
        border-radius: 5px;
        cursor: pointer;
        position: relative;
        border: 1px solid #dce6ee;
        &-img {
          display: inline-block;
          border: none;
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
        &-p {
          font-size: 16px;
          margin-top: 8px;
          width: 100%;
          height: 20px;
          text-indent: 0.5em;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
      }
    }
  }
}

.history {
  width: 100%;
  height: 500px;
  margin-top: 20px;
  margin-bottom: 20px;
  width: 100%;
  &-container:hover {
    box-shadow: 0px 5px 20px grey;
    border-radius: 10px;
  }
  &-container {
    transition: 0.5s;
    flex: 2.5;
    border: 1px solid #dadada;
    padding: 0px;
    margin-left: 20px;
    margin-right: 20px;
    color: #333333;
    height: 100%;
    &-course {
      &-item:hover {
        transform: translateY(-10px);
        box-shadow: 0px 10px 30px #888888;
      }
      &-item {
        list-style: none;
        float: left;
        width: 219px;
        height: 180px;
        margin-top: 10px;
        margin-left: 10px;
        transition: all 0.3s;
        border-radius: 5px;
        cursor: pointer;
        position: relative;
        border: 1px solid #dce6ee;
        &-img {
          display: inline-block;
          border: none;
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
        &-p {
          font-size: 16px;
          margin-top: 8px;
          width: 100%;
          height: 20px;
          text-indent: 0.5em;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
      }
    }
  }
}
</style>